package pl.taskman.controller;

import info.clearthought.layout.TableLayout;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JFrame;

import com.wordpress.tips4java.helper.ComponentMover;
import com.wordpress.tips4java.helper.ComponentResizer;

import pl.taskman.helper.ColorHelper;
import pl.taskman.model.NoteDTO;
import pl.taskman.model.UserDTO;
import pl.taskman.view.LoginViewPanel;


public class Main
{
	public Main()
	{
	}
	
	public void init()
	{		
		// MODELS
		NoteDTO noteDTO = new NoteDTO();
		UserDTO userDTO = new UserDTO();
		
		
		// CONTROLLERS
		DefaultController controller = new DefaultController();
		
		
		// VIEWS
		
		// TODO Controller as param
		LoginViewPanel loginViewPanel = new LoginViewPanel(ColorHelper.TURQUOISE);
//		CustomPanel loginViewPanel = new CustomPanel(new Color(51, 51, 51, 255));
//		MainViewPanel mainViewPanel = new MainViewPanel(controller);
		
		
		// INIT CONTROLLER
		controller.addModel(userDTO);
		controller.addModel(noteDTO);
//		controller.addView(loginViewPanel);
//		controller.addView(mainViewPanel);
		
		
		// INIT MODEL
//		userDTO.initDefault();
//		noteDTO.initDefault();
	
					// CREATE WINDOW
		//JWindow loginWindow = new JWindow();
		JFrame loginWindow = new JFrame();
		
		// INIT WINDOW
		Toolkit t = Toolkit.getDefaultToolkit(); 
        Dimension d = t.getScreenSize();
        
		// This is needed for setting the location
        Dimension loginWindowSize = new Dimension(350, 200);
        loginWindow.setSize(loginWindowSize);
        
        // Prevent resizing
		loginWindow.setMinimumSize(loginWindowSize);
		loginWindow.setMaximumSize(loginWindowSize);
		
        // This is needed for "pack" method
		loginWindow.setPreferredSize(loginWindowSize);
		
		loginWindow.setLocation(new Point((d.width / 2) - (loginWindow.getWidth() / 2), 
                        (d.height / 2) - (loginWindow.getHeight() / 2)));
		
		ComponentMover componentMover = new ComponentMover();
        ComponentResizer componentResizer = new ComponentResizer();
//        componentResizer.setMaximumSize(loginWindowSize);
         
        componentResizer.registerComponent(loginWindow);
        componentMover.registerComponent(loginWindow);
        
        // This is required to resize and move components at the same time
        componentMover.setDragInsets(componentResizer.getDragInsets());
        
        loginWindow.setName("TaskMan - Login");

        { 
              double size[][] = { { TableLayout.FILL }, { TableLayout.FILL } }; 
              loginWindow.setLayout(new TableLayout(size)); 
        }

        loginWindow.getContentPane().add(loginViewPanel, "0, 0");
        
        loginWindow.setUndecorated(true);
        
        // This causes the window to resize itself to preferredSize
        loginWindow.pack();
        loginWindow.setVisible(true);
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		Main main = new Main();
		main.init();
	}

}
